﻿using System;
using System.Windows.Forms;

namespace DOHS_WM6.Classes
{
    public class FormDOHS : Form
    {
        #region Atributos
        /// <summary>
        /// TextBox que sera alterado
        /// </summary>
        protected TextBox txtFocus;
        #endregion

        #region Eventos
        /// <summary>
        /// Escreve no TextBox que está com Focus
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button_Click(object sender, EventArgs e)
        {
            if (txtFocus != null)
            {
                if (txtFocus.Text.Length < txtFocus.MaxLength)
                    txtFocus.Text += ((Button)sender).Text;
                else
                    if (txtFocus.Text.Length == txtFocus.MaxLength)
                        txtFocus.Text = ((Button)sender).Text;
                if (txtFocus.Text.Length == txtFocus.MaxLength)
                    this.SelectNextControl((Control)txtFocus, true, true, true, true);
            }
        }

        /// <summary>
        /// Atribui TextBoxFocus para escrever no evento de click dos botoes do formulario
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void TextBoxGotFocus(object sender, EventArgs e)
        {
            txtFocus = (TextBox)sender;
        }

        /// <summary>
        /// Torna o formulario visível
        /// </summary>
        public virtual void MostraFormulario()
        {
            this.BringToFront();
        }
        #endregion
    }
}
